package com.wu.crud.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wu.crud.bean.Student;
import com.wu.crud.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 处理学生的CRUD操作
 */
@Controller
public class StudentController {

    @Autowired
    StudentService studentService;
    /**
     * 跳转到学生管理页面
     * @return
     */
    @RequestMapping("/Xueshen")
    public String gotoXueShen(
            @RequestParam(value = "pn", defaultValue = "1") Integer pn, Model model){
        PageHelper.startPage(pn, 4);
        List<Student> students = studentService.getAllStu();
        PageInfo page = new PageInfo(students, 5);
        model.addAttribute("stu_Info", page);
        return "Xueshen";
    }

    /**
     * 跳转到学生添加页面
     * @return
     */
    @RequestMapping("/Xueshen_2")
    public String gotoXueShen_2(){
        return "Xueshen_2";
    }

    /**
     * 跳转到学生修改页面
     * @return
     */
    @RequestMapping("/Xueshen_3")
    public String gotoXueShen_3(){
        return "Xueshen_3";
    }
}
